/*                                    _
 *   ___ _ __ ___ _ __ ___   ___   __| |
 *  / __| '__/ __| '_ ` _ \ / _ \ / _` |
 *  \__ \ |  \__ \ | | | | | (_) | (_| |
 *  |___/_|  |___/_| |_| |_|\___/ \__,_|      
 *
 *           _  _ _. _  _ . _  _ 
 *        \/(/_| _\|(_)| ||| |(_|
 *                             _|
 *     __|_ _ _|_ _   |_  _ | _  _  _
 *    _\ | (_| | (/_  | |(/_||_)(/_| 
 *                          |                                 
 ******************************************
 ******************************************
 ******************************************
 *  _    |_ |. _   |`    _  __|_. _  _  _
 * |_)|_||_)||(_  ~|~|_|| |(_ | |(_)| |_\
 * |                                     
 *		// Ensures that all external version dependencies are satisfied
 *		Versioning_CheckDependencies()
 *
 ******************************************
 ******************************************
 ******************************************
 * . _ _  _ | _  _ _  _  _ _|_ _ _|_. _  _ 
 * || | ||_)|(/_| | |(/_| | | (_| | |(_)| |
 *       |                                 
 *		At compile-time this provides verification that we are building
 *		against left4downtown.inc. It doesn't yet verify the right version,
 *		so it would be possible to build against the older one but then 
 *		it wouldn't run anyway due to the version check.
 *
 *		Everything else is a runtime check. It checks for the version CVARs
 *		for sourcemod_version and left4downtown_version to be the required
 *		versions or newer by parsing the a.b.c.d into an integer 
 * 		roughly equivalent to the 4 bytes `a b c d` if laid out in big endian
 *		memory.
 */
 

Versioning_CheckDependencies()
{
	RequireL4D();
}

/* parse a version string such as "1.2.3.4", up to 4 subversions allowed */
stock ParseVersionNumber(const String:versionText[])
{
	new String:versionNumbers[4][4];
	ExplodeString(versionText, /* split */ ".", versionNumbers, .maxStrings = 4, .maxStringLength = 4);
	
	new version = 0;
	new shift = 24;
	for(new i = 0; i < sizeof(versionNumbers); i++)
	{
		version = version | (StringToInt(versionNumbers[i]) << shift);
		
		shift -= 8;
	}
	
	//Debug_Print("Parsed version '%s' as %x", versionText, version);
	return version;
}

stock RequireL4D()
{
	decl String:gameName[64];
	GetGameFolderName(gameName, sizeof(gameName));
	if (!StrEqual(gameName, "left4dead", .caseSensitive = false))
	{
		SetFailState("Plugin supports Left 4 Dead only.");
	}
}